package com.zhijian.medical.service;

import com.github.pagehelper.PageHelper;
import com.zhijian.medical.dao.local.RoutineSampleTemplateMapper;
import com.zhijian.medical.entity.po.RoutineSampleTemplate;
import com.zhijian.medical.entity.vo.request.RoutineSampleTemplateSearchVo;
import com.zhijian.util.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoutineSampleTemplateService {

    @Autowired
    RoutineSampleTemplateMapper routineSampleTemplateMapper;

    public RoutineSampleTemplate addTemplate(RoutineSampleTemplate routineSampleTemplate){
        Date now = new Date();
        routineSampleTemplate.setCreateTime(now);
        routineSampleTemplate.setUpdateTime(now);
        routineSampleTemplateMapper.insert(routineSampleTemplate);
        return routineSampleTemplate;
    }

    public RoutineSampleTemplate updateTemplate(RoutineSampleTemplate routineSampleTemplate){
        Date now = new Date();
        routineSampleTemplate.setUpdateTime(now);
        routineSampleTemplateMapper.updateById(routineSampleTemplate);
        return routineSampleTemplate;
    }

    public void deleteTemplate(Long id){
        routineSampleTemplateMapper.deleteById(id);
    }

    public Page<RoutineSampleTemplate> selectPage(RoutineSampleTemplateSearchVo routineSampleTemplateSearchVo){
        PageHelper.startPage(routineSampleTemplateSearchVo.getPageNum(), routineSampleTemplateSearchVo.getPageSize());
        com.github.pagehelper.Page<RoutineSampleTemplate> orgData =
                routineSampleTemplateMapper.selectPage(routineSampleTemplateSearchVo);
        Page<RoutineSampleTemplate> dataList =
                new com.zhijian.util.page.Page<>(true, Integer.parseInt( String.valueOf(orgData.getTotal())), routineSampleTemplateSearchVo.getPageNum(), routineSampleTemplateSearchVo.getPageSize());
        dataList.setData(orgData);
        return dataList;
    }

    public List<RoutineSampleTemplate> selectList(RoutineSampleTemplateSearchVo routineSampleTemplateSearchVo){
        return  routineSampleTemplateMapper.selectList(routineSampleTemplateSearchVo);
    }
}
